Increment and Decrement Operators

Visualizing `A++`, `A--`, `++A`, `--A` and their subtle differences.

Postfix (`A++`, `A--`)

In **postfix** operations, the *original* value of the variable is returned first, and then the variable is incremented or decremented. The value of the expression is the value *before* the change.

let x = 5;
let y = x++; // y is 5, x is 6

Postfix Increment (A++)

Initial `valueA`:

Expression: `result = valueA++`

Result of expression:

Final `valueA`:

Postfix Decrement (A--)

Initial `valueB`:

Expression: `result = valueB--`

Result of expression:

Final `valueB`:


Prefix (`++A`, `--A`)

In **prefix** operations, the variable is incremented or decremented *first*, and then its *new* value is returned. The value of the expression is the value *after* the change.

let x = 5;
let y = ++x; // y is 6, x is 6

Prefix Increment (++A)

Initial `valueC`:

Expression: `result = ++valueC`

Result of expression:

Final `valueC`:

Prefix Decrement (--A)

Initial `valueD`:

Expression: `result = --valueD`

Result of expression:

Final `valueD`: